﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;

namespace Common
{
   public  class OperateConfig
    {
       
      
      
        public static string[] GetAcceptServerConfig()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            string[] config = new string[8];
            config[0] = myini.ReadString("SERVERCONFIG", "AcceptServerIp", "127.0.0.1");
            config[1] = myini.ReadString("SERVERCONFIG", "AcceptServerWebIp", "127.0.0.1");
 
            config[2] = myini.ReadString("DBCONFIG", "DataBaseName", "TaxiDispatchSystem");
            config[3] = myini.ReadString("DBCONFIG", "ServerName", "127.0.0.1");
            config[4] = myini.ReadString("DBCONFIG", "UserID", "root");
            config[5] = myini.ReadString("DBCONFIG", "PassWord", "123456");

            return config;
        }


        public static string[] GetControlCardConfig()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            string[] config = new string[2];
            config[0] = myini.ReadString("SERVERCONFIG", "out", "10,11,12,13,14,15,16,17");
            config[1] = myini.ReadString("SERVERCONFIG", "in", "0001");
            return config;
        }

        /// <summary>
        /// Save AcceptServer Config[]  0--PositionServerIP ,1--AcceptServerIp
        /// </summary>
        /// <param name="config"></param>
        public static void SaveAcceptServerConfig(string[] config)
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");

            myini.WriteString("SERVERCONFIG", "AcceptServerIp", config[0]);
            myini.WriteString("SERVERCONFIG", "AcceptServerWebIp", config[1]);
        }

        
        public static string GetTheNewestClientVersion()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            string config = myini.ReadString("SERVERCONFIG", "ClientVersion", "1.0");         
            if(config=="1.0")
            {
                SaveTheNewestClientVersion(config);
            }
            return config;
        }

        /// <summary>
        /// Save AcceptServer Config[]  0--PositionServerIP ,1--AcceptServerIp
        /// </summary>
        /// <param name="config"></param>
        public static void SaveTheNewestClientVersion(string config)
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            myini.WriteString("SERVERCONFIG", "ClientVersion", config);            
        }
 
        /// <summary>
        /// 0-DataBaseName,1-ServerName,2-UserID，3-PassWord
        /// </summary>
        /// <param name="config"></param>
        public static void SaveAcceptServerDataBaseConfig(string[] config)
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            myini.WriteString("DBCONFIG", "DataBaseName", config[0]);
            myini.WriteString("DBCONFIG", "ServerName", config[1]);
            myini.WriteString("DBCONFIG", "UserID", config[2]);
            myini.WriteString("DBCONFIG", "PassWord", config[3]);

        }

 
        public static string GetCenterPhoneNumber()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            return myini.ReadString("SERVERCONFIG", "PhoneNumber", "18602789588");
        }

        public static string GetAdContent()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            return myini.ReadString("SERVERCONFIG", "AD", "");
        }

        public static string GetOffSetLongitude()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            return myini.ReadString("SERVERCONFIG", "OffSetLongitude", "00005723");
        }

 
        public static string GetOffSetLatitude()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            return myini.ReadString("SERVERCONFIG", "OffSetLatitude", "00002287");
        }

       /// <summary>
        /// 获取本地报警配置：
        /// 0：输出端口配置10,11,12,13,14,15,16,17 分别表示各个端口的开始截止时间段
        /// 1：输入端口报警是否启用，0为关闭，1为启用
        /// 2:报警短信发送的手机号码
       /// </summary>
       /// <returns></returns>
       public static string[] GetClientWarmingConfig()
       {
           IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
           string[] config = new string[3];
           config[0] = myini.ReadString("WARMINGCONFIG", "OutPut", "06,22,25,0,07,18,25,0");
           config[1] = myini.ReadString("WARMINGCONFIG", "InPut", "0011");
           config[2] = myini.ReadString("WARMINGCONFIG", "WarmingCall", "18627704749");
           if (config[0] == "06,22,25,0,07,18,25,0" && config[1] == "0011"
               && config[2] == "18627704749")
           {
               SaveClientWarmingConfig(config);
           }
           return config;
       }

       /// <summary>
       /// 保存客户端报警配置：config[0]: 输出端口时间段（格式为06,22,25,0,07,18,25,0）
       /// config[1]: 输入端口是否开启（0011）  config[2]: 短信报警发送号码
       /// </summary>
       /// <param name="config"></param>
       public static void SaveClientWarmingConfig(string[] config)
       {
           IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
           myini.WriteString("WARMINGCONFIG", "OutPut", config[0]);
           myini.WriteString("WARMINGCONFIG", "InPut", config[1]);
           myini.WriteString("WARMINGCONFIG", "WarmingCall", config[2]);          
       }
       /// <summary>
       /// 获取配置文件信息  0：服务器IP, 1：端口 ,2：发送搜车命令的休息时间 ,3：当前站点,
       ///  4：下一站, 5：本站手机号 ,6：广告内容,7:窗体是否TopMost(为1时表示是，其它表示否)
       /// </summary>
       /// <returns></returns>
        public static string[] GetClientConfig()
        {
            string[] config = new string[8];
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            config[0] = myini.ReadString("SERVERCONFIG", "SERVERIP", "gqcbus.cityofcar.com");
            config[1] = myini.ReadString("SERVERCONFIG", "SERVERPORT", ConstParameters.AstPort.ToString());
            config[2] = myini.ReadString("SERVERCONFIG", "UPDATESLEEPTIME", "10000");
            config[3] = myini.ReadString("SERVERCONFIG", "CURRENTSTATION", "");
            config[4] = myini.ReadString("SERVERCONFIG", "NEXTSTATION", "");
            config[5] = myini.ReadString("SERVERCONFIG", "PHONENUMBER", "000000000000");
            config[6] = myini.ReadString("SERVERCONFIG", "ADCONTENT", "").Trim('\0');
            config[7] = myini.ReadString("SERVERCONFIG", "IsTopMost", "1").Trim('\0');
            
            if (config[0] == "gqcbus.cityofcar.com" 
                && config[1] == ConstParameters.AstPort.ToString() 
                && config[2] == "10000"
                && config[3] == ""
                && config[4] == ""
                && config[5] == "000000000000"
                && config[6] == "" 
                && config[7] == "1")
            {
                SaveClientConfig(config);
            }
            return config;
        }

        public static void SaveClientConfig(string[] config)
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            myini.WriteString("SERVERCONFIG", "SERVERIP", config[0]);
            myini.WriteString("SERVERCONFIG", "SERVERPORT", config[1]);
            myini.WriteString("SERVERCONFIG", "UPDATESLEEPTIME", config[2]);
            myini.WriteString("SERVERCONFIG", "CURRENTSTATION", config[3]);
            myini.WriteString("SERVERCONFIG", "NEXTSTATION", config[4]);
            myini.WriteString("SERVERCONFIG", "PHONENUMBER", config[5]);
            myini.WriteString("SERVERCONFIG", "ADCONTENT", config[6]);
            myini.WriteString("SERVERCONFIG", "IsTopMost", config[7]);         
        }
        

       public static string[] GetComConfig()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            string[] config = new string[3];
            config[0] = myini.ReadString("SERVERCONFIG", "CameraComPort", "COM1");
            config[1] = myini.ReadString("SERVERCONFIG", "ControlCardComPort", "COM2");
            config[2] = myini.ReadString("SERVERCONFIG", "TakePhotoSpaceTime", "600");
            if (config[0] == "COM1" && config[1] == "COM2" && config[2]=="600")
            {
                SaveComConfig(config);
            }
            return config;
        }

        public static void SaveComConfig(string[] config)
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            myini.WriteString("SERVERCONFIG", "CameraComPort", config[0]);
            myini.WriteString("SERVERCONFIG", "ControlCardComPort", config[1]);
            myini.WriteString("SERVERCONFIG", "TakePhotoSpaceTime", config[2]);
        }

        public static string[] GetClinetMapPointAndZoom()
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            string lat= myini.ReadString("SERVERCONFIG", "LAT", "29.24828790");
            string lng = myini.ReadString("SERVERCONFIG", "LNG", "115.78491210");
            string zoom = myini.ReadString("SERVERCONFIG", "ZOOM", "14");
            string[] info = {lat,lng,zoom};
            if (lat == "29.24828790" && lng == "115.78491210" && zoom == "14")
            {
                SaveClinetMapPointAndZoom(info);
            }
            return info;
        }

        public static void SaveClinetMapPointAndZoom(string[] config)
        {
            IniFiles myini = new IniFiles(System.Environment.CurrentDirectory + "\\system.ini");
            myini.WriteString("SERVERCONFIG", "LAT", config[0]);
            myini.WriteString("SERVERCONFIG", "LNG", config[1]);
            myini.WriteString("SERVERCONFIG", "ZOOM", config[2]);                
        }
    }
}
